package 适配器模式.快排和二分查找;

public class BinarySearch {
    public int binarySearch(int[] array,int target){
        System.out.println("我是二分查找");
        return binarySearch(target, array, 0, array.length-1);
    }

    //重载一下二分查找
    public  int binarySearch(int key,int[] array,int low,int high){
        //防越界
        if (key < array[low] || key > array[high] || low > high) {
            return -1;
        }
        int middle = (low+high)/2;
        if(array[middle]>key){
            //大于关键字
            return  binarySearch(key,array,low,middle-1);
        }else if(array[middle]<key){
            //小于关键字
            return binarySearch(key,array,middle+1,high);
        }else{
            return array[middle];
        }
    }
}
